package edu.bit.water.service;

import edu.bit.water.dao.MetaCleanProductDao;
import edu.bit.water.entity.MetaCleanProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MetaCleanProductService {
    @Autowired
    private MetaCleanProductDao metaCleanProductDao;

    // 查询
    public List<MetaCleanProduct> select() {
        List<MetaCleanProduct> list = metaCleanProductDao.select();
        return list;
    }

    // 新增
    public Map<String, Object> insert(MetaCleanProduct metaCleanProduct) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductDao.insert(metaCleanProduct);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 编辑
    public Map<String, Object> update(MetaCleanProduct metaCleanProduct) {
        Map<String, Object> map = new HashMap<>();
        int n = metaCleanProductDao.update(metaCleanProduct);
        if (n == 1) {
            map.put("status", "success");
        } else {
            map.put("status", "failed");
        }
        return map;
    }

    // 删除
    public int delete(List<Integer> ids) {
        try {
            for (Integer id : ids) {
                metaCleanProductDao.delete(id);
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }

    // 删除全部子页面数据
    public int deleteSub(List<Integer> ids) {
        try {
            for (Integer id : ids) {
                metaCleanProductDao.deleteSub1(id);
                metaCleanProductDao.deleteSub2(id);
                metaCleanProductDao.deleteSub3(id);
                metaCleanProductDao.deleteSub4(id);
                metaCleanProductDao.deleteSub5(id);
            }
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }

    //更改清洁生产功能页面的标准状态
    public void updateStatus(String standardNumber, String standardStatus) {
        metaCleanProductDao.updateStatus(standardNumber, standardStatus);
    }
}
